<template>

  <el-container class="el-container">
    <el-header class="el-header">

      <img class="logo" src="../assets/cc.webp" alt="">
      <h4>xxx信息管理系统</h4>
      <div class="userInfo">
        <img class="icon" :src="icon" alt="">
        <span>{{ name }}</span>
        <el-button round size="mini" type="primary" @click="exit">退出</el-button>
      </div>
    </el-header>
    <el-container>
      <el-aside width="200px" class="el-aside">
        <el-menu
            :default-active="this.def_url"
            router
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b">
              <!--一级菜单-->
          <el-submenu :index="menu.id+''"  v-for="(menu,index) in menus">
            <template slot="title">
              <i :class="menus_icon[index]"></i>
              <span>{{menu.name}}</span>
            </template>
            <!--二级菜单-->
              <el-menu-item :index="son_menu.url" @click="changeActiveMenu(son_menu.url)" v-for="son_menu in menu.son_menus" >
                <template slot="title">
                  <i class="el-icon-date"></i>
                  <span>{{son_menu.name}}</span>
                </template>

              </el-menu-item>
            </el-submenu>

        </el-menu>
      </el-aside>
      <el-container>
        <el-main class="el-main">
          <router-view></router-view>
        </el-main>
        <el-footer class="el-footer">Footer</el-footer>
      </el-container>
    </el-container>
  </el-container>

</template>

<script>
export default {
  data() {
    return {
      def_url:"user_list",
      menus:[],
       menus_icon:["el-icon-s-tools","el-icon-s-custom","el-icon-s-shop","el-icon-s-order","el-icon-s-marketing",]
    }
  },
  created() {
    this.getMenus()
    const url = window.sessionStorage.getItem("url")
      if(url){
        this.def_url=url
      }
  },
  computed: {
    name() {
      return sessionStorage.getItem("name");
    },
    icon() {
      return sessionStorage.getItem("icon");
    }
  },

  name: "Home",
  methods: {
     changeActiveMenu(url){
        if(url!=null && ""!=url){
          window.sessionStorage.setItem('url',url)
        }
      },
    exit() {
      window.localStorage.clear()
      window.sessionStorage.clear()
      this.$confirm('此操作将退出系统, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // 退出登录
        this.$router.push("/login");
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消退出'
        });
      });
    },
    // 获取菜单
    async getMenus() {
      let {data:res} = await this.$axios.get("menus/getMenus")
        console.log(res);
        this.menus = res.data
    }
  }
}
</script>

<style scoped>
.el-header{
  display: flex;
  justify-content: space-between;
}
.el-header, .el-footer {
  background-color: rgb(53,61,64);
  color:white;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: rgb(4,42,63);
  color: white;
  text-align: center;
  line-height: 200px;
}

.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
  line-height: 160px;
}

.el-container {
  height: 100%;
}

.el-container:nth-child(5) .el-aside,
.el-container:nth-child(6) .el-aside {
  line-height: 260px;
}

.el-container:nth-child(7) .el-aside {
  line-height: 320px;
}

.logo{
  width: 50px;
  height: 50px;
  border-radius: 50%;
  vertical-align: middle;
  margin-top: 5px;
}
.icon{
  width: 35px;
  height: 35px;
  border-radius: 50%;
  vertical-align: middle;
}
.userInfo{
  width: 12%;
}
.userInfo span{
  margin: auto 10px;
}
</style>